#include "Reader.h"
#include <iostream>
#include <fstream>

#define SIZE_AVERAGE_FILE 20000
#define SIZE_MAX_LINE     500
//TODO: Different strategy needed

using namespace std;

Reader::Reader(void)
{
    m_sStream.reserve(SIZE_AVERAGE_FILE);
    m_nCursor = -1;
    //Marking as invalid
	m_nLines  = 0;
}

Reader::~Reader(void)
{
}

void Reader::gobble(string inFilename)
{
    ifstream xInFile(inFilename.c_str());
	if(!xInFile)
	{
		cerr<< inFilename << " import failed." <<endl;
		return; //TODO: raise exception
	}

	std::string line;
	while(std::getline(xInFile, line)) {
		m_nLines++;
		m_sStream.append(line);
        m_sStream.push_back('\n');
	}
    
    xInFile.close();
}

char Reader::spit(void)
{
    return m_sStream[m_nCursor++];
}

bool Reader::isFinished(void)
{
    if(m_nCursor >= (signed int)m_sStream.length())
    {
        return true;
    }
    return false;
}

string Reader::getStream(void)
{
    return m_sStream;
}